//全局服务
var myAppService = angular.module('myApp');
myAppService.factory('CookieService',function(){
    var setCookie = function(c_name,c_value,expireTime){
        var exdate = new Date();
        exdate.setDate(exdate.getDate() + expireTime);
        document.cookie=c_name+ "=" +escape(c_value)+
            ((expireTime==null) ? "" : ";expires="+exdate.toGMTString())
    };
    var getCookie = function(c_name){
        if (document.cookie.length>0)
        {
            c_start=document.cookie.indexOf(c_name + "=")
            if (c_start!=-1)
            {
                c_start=c_start + c_name.length+1
                c_end=document.cookie.indexOf(";",c_start)
                if (c_end==-1) c_end=document.cookie.length
                return unescape(document.cookie.substring(c_start,c_end))
            }
        }
        return "";
    };
    var delCookie = function(c_name){
        var exp = new Date();
        exp.setTime(exp.getTime() + (-1 * 24 * 60 * 60 * 1000));
        var cval = getCookie(c_name);
        document.cookie = c_name + "=" + cval + "; expires=" + exp.toGMTString();
    }
    return{
        setCookie:function(c_name,c_value,expireTime){
            return setCookie(c_name,c_value,expireTime);
        },
        getCookie:function(c_name){
            return getCookie(c_name);
        },
        delCookie:function(c_name){
            return delCookie(c_name);
        }
    }
})

//用户名模块的服务
var userService = angular.module('User');
userService.factory('UserExistsService',function($http,rootPath){
    var runRequest = function(account){
        $http({
            method:'GET',
            url:rootPath+'/existsAccount',
            param:{account:account}
        }).success(function(data){
            return data;
        }).error(function(data){
            alert(1111);
        })
    };
    return{
        isExists:function(account){
            return runRequest(account);
        }
    }
});


